﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using HtmlAgilityPack;
using System.Net;
using System.IO;

namespace NeuralStock.Tools
{
    public class BaseDownloader
    {
        protected HtmlDocument DownloadAndLoad(string address, string filePath)
        {
            using (WebClient client = new WebClient())
            {
                client.DownloadFile(address, filePath);
            }

            HtmlDocument doc = new HtmlDocument();
            doc.Load(filePath);

            return doc;
        }

        protected decimal? ParseDecimal(string input)
        {
            if (input.Contains('-')
                || input.Contains('x'))
            {
                return null;
            }

            Regex digitsOnly = new Regex(@"[^\d,.]");
            input = digitsOnly.Replace(input, "");

            input = input.Replace(',', '.');

            return decimal.Parse(input, CultureInfo.InvariantCulture);
        }
    }
}
